/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.clinicplus.manager.search;

import br.com.foxline.clinicplus.entity.Operator;
import br.com.foxline.clinicplus.entity.Procedure;
import br.com.foxline.clinicplus.service.OperatorService;
import br.com.foxline.clinicplus.service.ProcedureService;
import br.com.foxline.clinicplus.util.Msg;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author ely
 */
@ManagedBean
@ViewScoped
public class ManagerSearchOperator {

    @EJB
    OperatorService operatorService;
    @EJB
    ProcedureService procedureService;
    private Operator searchOperator;
    private List<Operator> operators;
    private List<Procedure> procedures;
    private Operator editOperator;
    private Operator showOpe;
    private String opeEdit;
    private String opeShow;

    @PostConstruct
    public void init() {
        searchOperator = new Operator();
        operators = new ArrayList<Operator>();

        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        opeEdit = params.get("opeEdit");
        opeShow = params.get("opeShow");

        paramPost();
    }

    public void paramPost() {
        try {
            if (opeShow != null) {
                showOpe = operatorService.find(Long.parseLong(opeShow));
                procedures = procedureService.findProcedureOperator(showOpe);
//               showGroups = groupService.findGroups(showUser);
//               showUser.setGroups(showGroups);
            } else if (opeEdit != null) {
                editOperator = operatorService.find(Long.parseLong(opeEdit));

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public BigDecimal valueProcedure(Procedure p) {
        return procedureService.getValueProcedureOperator(p, showOpe);
    }

    public void update() {
        try {
            operatorService.update(editOperator);
            Msg.messagemInfo("Convenio Atualizado com Sucesso ");
        } catch (Exception erro) {
        }
    }

    public void listOperator() {
        operators = operatorService.findOperator(searchOperator);
    }

    public Operator getSearchOperator() {
        return searchOperator;
    }

    public void setSearchOperator(Operator searchOperator) {
        this.searchOperator = searchOperator;
    }

    public List<Operator> getOperators() {
        return operators;
    }

    public void setOperators(List<Operator> operators) {
        this.operators = operators;
    }

    public Operator getEditOperator() {
        return editOperator;
    }

    public void setEditOperator(Operator editOperator) {
        this.editOperator = editOperator;
    }

    public Operator getShowOpe() {
        return showOpe;
    }

    public void setShowOpe(Operator showOpe) {
        this.showOpe = showOpe;
    }

    public List<Procedure> getProcedures() {
        return procedures;
    }

    public void setProcedures(List<Procedure> procedures) {
        this.procedures = procedures;
    }
}
